package com.siping.算法;

/**
 * @author Yang Xu
 * @date 2021/9/6 14:31
 * @description:
 */
public class ShellSort {

    public static void main(String[] args) {
        int[] arr = {2, 1, 4, 3, 2, 99, 32, 44};
        sort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }

    public static void sort(int[] arr) {
        int gap = arr.length;
        for (int k = 0; k < gap; k++) {
            gap = gap / 2;
            for (int i = k + 2 * gap - 1; i < arr.length; i += gap) {
                for (int j = i; j > 0; j--) {
                    if (arr[j] < arr[j - 1]) {
                        int tmp = arr[j];
                        arr[j] = arr[j - 1];
                        arr[j - 1] = tmp;
                    }
                }
            }
        }


    }
}
